<template>
  <el-card>
<!--    <el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">-->

<!--    </el-form>-->
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%">
      <el-table-column prop="id" label="编号" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="name" label="课程名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="teacherName" label="教师" header-align="center" align="center"></el-table-column>
      <el-table-column label="可选人数" header-align="center" align="center">
        <template #default="scope">
            {{ scope.row.selected + " / "+ scope.row.maxNum}}
        </template>
      </el-table-column>
<!--      <el-table-column prop="maxNum" label="已选人数" header-align="center" align="center"></el-table-column>-->
      <fastTableColumn prop="type" label="课程类型" dictType="course_type"></fastTableColumn>
<!--      <el-table-column prop="name" label="创建者" header-align="center" align="center"></el-table-column>-->
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template #default="scope">
          <el-button  v-if="scope.row.opt" type="info" disabled  link>已选择</el-button>
          <el-button v-else-if="scope.row.selected < scope.row.maxNum" type="primary" link @click="courseSelectionResults(scope.row.id)">选课</el-button>
          <el-button v-else type="danger" disabled link>已选满</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="state.page"
      :page-sizes="state.pageSizes!"
      :page-size="state.limit"
      :total="state.total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
    />
  </el-card>
</template>

<script setup lang="ts">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'

import { IHooksOptions } from '@/hooks/interface'
import fastTableColumn from "@/components/fast-table-column";
import { geometrycollectionListApi } from "@/api/coursechoose/coursechoose";
import { ElMessage } from "element-plus";
const state: IHooksOptions = reactive({
  dataListUrl: 's/course/page',
})
function  courseSelectionResults(id:string){
  geometrycollectionListApi(id).then(()=>{
    ElMessage.success("选课成功")
    getDataList()
  })
}

const { getDataList , sizeChangeHandle , currentChangeHandle} = useCrud(state)
</script>
